const webpack = require('webpack');
const merge = require('webpack-merge');
const ExtractCssChunks = require('extract-css-chunks-webpack-plugin');

const webpackBaseConfig = require('./webpack.config.base');

const webpackProdConfig = merge(webpackBaseConfig, {
    devtool: false,
    mode: 'production',
    optimization: {
        runtimeChunk: {
            name: 'ml-node'
        },
        splitChunks: {
            cacheGroups: {
                commons: {
                    chunks: 'initial',
                    minChunks: 5
                },
                vendor: {
                    chunks: 'all',
                    name: 'vendor',
                    test: /node_modules/,
                    priority: -10,
                    reuseExistingChunk: false
                }
            }
        }
    },
    plugins: [
        new webpack.DefinePlugin({
            'process.env': {
                NODE_ENV: JSON.stringify('production')
            }
        }),
        new ExtractCssChunks({
            filename: 'assets/css/[name].[chunkhash:8].css',
            chunkFilename: 'asserts/css/[id].[chunkhash:8].css'
        }),
        new webpack.optimize.MinChunkSizePlugin({
            minChunkSize: 20000
        })
    ]
})